package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.ProcessType;
import com.stylefeng.guns.modular.system.service.IProcessTypeService;

/**
 * 流程类别控制器
 *
 * @author fengshuonan
 * @Date 2019-06-20 09:00:50
 */
@Controller
@RequestMapping("/processType")
public class ProcessTypeController extends BaseController {

    private String PREFIX = "/system/processType/";

    @Autowired
    private IProcessTypeService processTypeService;

    /**
     * 跳转到流程类别首页
     */
    @RequestMapping("/procedure_type")
    public String index() {
        return PREFIX + "processType.html";
    }

    /**
     * 跳转到添加流程类别
     */
    @RequestMapping("/processType_add")
    public String processTypeAdd() {
        return PREFIX + "processType_add.html";
    }

    /**
     * 跳转到修改流程类别
     */
    @RequestMapping("/processType_update/{processTypeId}")
    public String processTypeUpdate(@PathVariable Integer processTypeId, Model model) {
        ProcessType processType = processTypeService.selectById(processTypeId);
        model.addAttribute("item",processType);
        LogObjectHolder.me().set(processType);
        return PREFIX + "processType_edit.html";
    }

    /**
     * 获取流程类别列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return processTypeService.selectList(null);
    }

    /**
     * 新增流程类别
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ProcessType processType) {
        processTypeService.insert(processType);
        return SUCCESS_TIP;
    }

    /**
     * 删除流程类别
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer processTypeId) {
        processTypeService.deleteById(processTypeId);
        return SUCCESS_TIP;
    }

    /**
     * 修改流程类别
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ProcessType processType) {
        processTypeService.updateById(processType);
        return SUCCESS_TIP;
    }

    /**
     * 流程类别详情
     */
    @RequestMapping(value = "/detail/{processTypeId}")
    @ResponseBody
    public Object detail(@PathVariable("processTypeId") Integer processTypeId) {
        return processTypeService.selectById(processTypeId);
    }
}
